package com.cloud.rest.api;

import com.cloud.rest.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActionFactory {

	private static ActionFactory instance; 
	private static Map<String,Action> actionsMap;
	
	private ActionFactory() {
		actionsMap = new HashMap<String,Action>();
		
		List<String> reqParam = new ArrayList<String>();
		reqParam.add(RestAPIServlet.PARAM_BUCKET);
		reqParam.add(RestAPIServlet.PARAM_TOP);
		Action actionQuery = new Action(RestAPIServlet.ACTION_QUERY,
				                        reqParam,
				                        null);
		actionsMap.put(RestAPIServlet.ACTION_QUERY, actionQuery);
		
		reqParam = new ArrayList<String>();
		reqParam.add(RestAPIServlet.PARAM_BUCKET);
		Action actionCreate = new Action(RestAPIServlet.ACTION_CREATE,
				                        reqParam,
				                        null);
		actionsMap.put(RestAPIServlet.ACTION_CREATE, actionCreate);
		
		reqParam = new ArrayList<String>();
		reqParam.add(RestAPIServlet.PARAM_BUCKET);
		reqParam.add(RestAPIServlet.PARAM_ID);
		reqParam.add(RestAPIServlet.PARAM_SCORE);
		Action actionInsert = new Action(RestAPIServlet.ACTION_INSERT,
				                        reqParam,
				                        null);
		actionsMap.put(RestAPIServlet.ACTION_INSERT, actionInsert);
	}
	
	public static ActionFactory getInstance() {
		if (instance == null)
			instance = new ActionFactory();
		return instance;
	}
	
	public static Map<String,Action> getActionsMap() {
		return ActionFactory.actionsMap;
	}
	
	public static Action getActionByName(String actionName) {
		return actionsMap.get(actionName);
	}
}
